package ink.metoo.auto.fishpi.chatroom.command

import ink.metoo.auto.fishpi.Log
import ink.metoo.auto.fishpi.call.UserCall
import ink.metoo.auto.fishpi.chatroom.Message
import ink.metoo.auto.fishpi.job.GuessingRiddleGameJob

class GuessGuessingRiddleCommand : Command {

    override val commandText: String = "/解谜"

    override val alias: Array<String> = arrayOf("/解密", "解谜", "解密")

    override val commandTypes: Array<Command.Type> = arrayOf(Command.Type.OTHER_CLIENT)

    override fun execute(message: Message) {
        val params = message.commandParams
        val answer = params.getOrNull(1) ?: return
        val gr = GuessingRiddleGameJob.guessingRiddle ?: return
        if (gr.getSimpleMd() != answer) return
        val result = UserCall.transfer(message.userName!!, (10..32).random(), "猜对了【${gr.mt}】谜语")
        Log.info("transfer result: ${result.code} ${result.msg}")
        GuessingRiddleGameJob.deletePreviousGuessingRiddle()
    }

}
